package com.b2bpsssm.service.impl;

import com.b2bpsssm.common.R;
import com.b2bpsssm.mapper.OtherExpensesMapper;
import com.b2bpsssm.pojo.Other_Expenses;
import com.b2bpsssm.service.OtherExpensesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OtherExpensesServicelmpl  implements OtherExpensesService {
    @Autowired
    private OtherExpensesMapper otherExpensesMapper;
       //查询其他支出 有分页
    @Override
    public R queryOtherExpensesList(Integer currentPage, Integer pageSize) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        //查询后的数据
        List<Other_Expenses> other_expenses = otherExpensesMapper.queryOtherExpensesList(start, off);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(other_expenses);
        return r;
    }
     //以其他支出为关键字 时间范围 进行关键字查询
    @Override
    public R selOtherExpensesLikeType(Integer currentPage, Integer pageSize, String other_expense_creation_time1, String other_expense_creation_time2, String other_expense_payment_type) {
        R r = new R();
        Integer start = (currentPage - 1) * pageSize;//分页第一个参数
        Integer off = pageSize; //分页第二个参数
        List<Other_Expenses> list = otherExpensesMapper.selOtherExpensesLikeType(start, off,other_expense_creation_time1, other_expense_creation_time2,other_expense_payment_type);
        //成功后返回的结果
        r.setCode(200);
        r.setMassage("success");
        r.setData(list);

        return r;
    }
   //新增其他支出
    @Override
    public R addOtherExpenses(Other_Expenses other_expenses) {
        R r = new R();
        try {
            int result = otherExpensesMapper.addOtherExpenses(other_expenses);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;

    }

    @Override
    public R updateOtherExpenses(Other_Expenses other_expenses) {

        R r = new R();

        try {
            int result =otherExpensesMapper.updateOtherExpenses(other_expenses);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("修改成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;
    }
    //根据编号删除
    @Override
    public R delOtherExpensesByNumber(Other_Expenses other_expense_bills) {
        R r = new R();

        try {
            int result = otherExpensesMapper.delOtherExpensesByNumber(other_expense_bills);
            if (result > 0) {
                r.setCode(200);
                r.setMassage("删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMassage("系统开小差了，请联系管理员！");
        }
        return r;
    }


}
